#include "rfidsensor.h"
#include "rfidsensortest.h"
#include "ui_rfidsensortest.h"

RFIDSensorTest::RFIDSensorTest(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RFIDSensorTest)
{
    ui->setupUi(this);
    rfidSensor = new RfidSensor("/tcrwork/linuxController/trunk/TcrController/data/globalConfig/rfidSensor/rfidSensor.xml");
    timer.start(200);
    QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(on_Button_ReadTag_clicked()));
}

RFIDSensorTest::~RFIDSensorTest()
{
    delete ui;
}

void RFIDSensorTest::on_Button_ReadTag_clicked()
{
//    int deviceId = ui->Edit_RDID_DeviceId->text().toInt();
    QString value;
    double readTime;
    int resultKey = rfidSensor->getCurrentTagData(2, value,readTime);
    if(resultKey == -1)
    {
        ui->Button_ReadTag->setText("数据获取失败!");
        ui->Edit_RDID_DeviceId->setText(QString("%1").arg(readTime));
        ui->Edit_TagData->setText(QString("%1").arg(value));
        ui->label->setText(QString("%1").arg(resultKey));
    }
    else if(resultKey == 1)
    {
        ui->Button_ReadTag->setText("数据获取成功!");
        ui->Edit_TagData->setText(QString("%1").arg(value));
        ui->Edit_RDID_DeviceId->setText(QString("%1").arg(readTime));
        ui->label->setText(QString("%1").arg(resultKey));
    }
    else
    {
        ui->Button_ReadTag->setText("卡片不在探测范围!");
        ui->Edit_TagData->setText(QString("%1").arg(value));
        ui->Edit_RDID_DeviceId->setText(QString("%1").arg(readTime));
        ui->label->setText(QString("%1").arg(resultKey));
    }
}
